JS - element properties - offsetParent

revision:


returns the offset container of an element.

top

The property returns the nearest ancestor that has a position other than static. The property returns null if the element is not visible (display="none").

Syntax:

element.offsetParent : the nearest positioned ancestor.

property value:

none :

example

My offsetParent is:

code:
                <div>
                    <div id="DIV">
                        <p>My offsetParent is: <span id="prop"></span></p>
                    </div>
                </div>
                <script>
                    const element = document.getElementById("DIV");
                    document.getElementById("prop").innerHTML = element.offsetParent;
                </script>